<?php
class Model_Category extends Model{

    //首页数据
    public function getPostInfo($assort,$offset=0,$pageSize=20){

        $data=DB::select(array('postid','id'),'title','introduction','description','tags','images','url','price','view','reach','review','created','wish','praiseup','praisedown')
        
        ->from('post')
        
        ->where('isdeleted','=','0')

        ->and_where('assort','=',$assort)

        ->order_by('sort','desc')
        
        ->order_by('praiseup','desc')

        ->order_by('view','desc')

        ->order_by('wish','desc')

        ->order_by('postid','desc')
        
        ->limit($pageSize)
        
        ->offset($offset)
        
        ->execute()->as_array();

        return $data;

    }

    //post总数
    public function getItems($assort){

         $total= DB::select(array(DB::expr('count(1)'), 'total'))

         ->from('post')

        ->where('isdeleted','=','0')

        ->and_where('assort','=',$assort)

        ->execute()

        ->get("total");

        return $total;

    }

    public function getInfoByUrl($url){

      $data=DB::select(array('assortid','id'))->from('assort')

      ->where("isdeleted",'=',0)

      ->and_where("url","=",$url)

      ->limit(1)

      ->execute()

      ->as_array();

      if(!empty($data)){

          $data=$data[0];

      }

      return $data;
    }
}